﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Testtt
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void DrawEllipse()
        {
            System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
            System.Drawing.Graphics formGraphics;
            formGraphics = this.CreateGraphics();
            formGraphics.DrawEllipse(myPen, new Rectangle(0, 0, 200, 300));
            myPen.Dispose();
            formGraphics.Dispose();
        }

        private void DrawRectangle()
        {
            System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
            System.Drawing.Graphics formGraphics;
            formGraphics = this.CreateGraphics();
            formGraphics.DrawRectangle(myPen, new Rectangle(0, 0, 200, 300));
            myPen.Dispose();
            formGraphics.Dispose();
        }

        public void InitGameSpace()
        {
            GameSpace.Width = this.Width;
            GameSpace.Height = this.Height;
            GameSpace.ArrBitBlock = new int[Height];
            GameSpace.MinBlockWidth = 10;
            GameSpace.Backbround = Color.Black;
            GameSpace.WinHandle = this.Handle;
            GameSpace.HasGrid = false;
            GameSpace.GridColor = Color.White;

            GameSpace.BlockColor = new Color[] { Color.LightCyan, Color.DarkSeaGreen, Color.Beige, Color.Beige, Color.Beige, Color.Beige, Color.Beige };
            GameSpace.BlockFore = new Color[] { Color.Blue, Color.Beige, Color.DarkKhaki, Color.DarkMagenta, Color.DarkOliveGreen, Color.DarkOrange, Color.DarkRed };
            this.BackColor = GameSpace.Backbround;
            m_StartLocation = new Point(100, 10);
        }

        private Block m_currentBlock;
        private Point m_StartLocation;
        private void button1_Click(object sender, EventArgs e)
        {
            m_currentBlock.Rotate();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            m_currentBlock.Down();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            m_currentBlock.Right();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            m_currentBlock.Left();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
        }

        private void button5_Click(object sender, EventArgs e)
        {
            InitGameSpace();
            m_StartLocation = new Point(GameSpace.MinBlockWidth * 15, 10);
            m_currentBlock = new Block(m_StartLocation, BlockType.undefined);
            m_currentBlock.Draw(this.Handle);
        }

        private void Form2_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Right: m_currentBlock.Right(); break;
                case Keys.Left: m_currentBlock.Left(); break;
                case Keys.Up: m_currentBlock.Rotate(); break;
                case Keys.Down: while (m_currentBlock.Down()) ; break;
                case Keys.Space:
                    break;
                case Keys.Enter:
                    button5_Click(null,null);
                    break;
            }
            this.Focus();
        }
    }
}
